﻿using System;
using System.Collections.Generic;
using System.Text;
using taxi_sovereign.interfaces;
using taxi_sovereign.model; 

namespace taxi_sovereign.controls
{
    public static class Editor
    {
        public static Model currmodel;
        public static Object chosenObject;
        public static _Constants._objecttype chosenType;
        
        public static bool edit = false;
        public static bool findcross = false;
        public static bool addcross = false;
        public static bool addroad = false;
        public static bool objectready = false;
        public static bool scrolling = false;
        public static bool moving = false;
        public static bool newroad = false;
        public static bool newcross = false;
        public static bool newstop = false;
        public static bool newvehicle = false;
        public static bool setroute = false;
        public static bool mergecrosses = false;
        
        

        public static void SetModel(IModel inputmodel)
        {
            currmodel = (Model)inputmodel;
        }

        public static void SetFalse()
        {
            findcross = false;
            addcross = false;
            addroad = false;
            objectready = false;
            newroad = false;
            newstop = false;
            newvehicle = false;
            setroute = false;
            mergecrosses = false;
        }

        public static void SetFirstObject(Object inputobject)
        {
            chosenObject = inputobject;
            if (inputobject is ICross)
            {
                chosenType = _Constants._objecttype.Cross;
            }
        }

        public static void NewCross(ICross inputcross)
        {
            currmodel.GetModelSettings().Crosses().Add(inputcross);
        }

        public static void NewCross(int inputx, int inputy)
        {
            currmodel.GetModelSettings().Crosses().Add(new Cross(inputx, inputy));
        }

        private static void NewRoadCrossToCross(ICross one, ICross two, string name)
        {
            IRoad newroad = new Road(one, two, name);
            currmodel.GetModelSettings().Roads().Add(newroad);
            one.AddRoad(newroad);
            two.AddRoad(newroad);
        }

        public static void NewRoadToPoint(int inputx, int inputy, string name)
        {
            NewroadCrossToPoint((ICross)chosenObject, inputx, inputy, name);
        }

        private static void NewroadCrossToPoint(ICross one, int pointx, int pointy, string name)
        {
            ICross newcross = new Cross(pointx, pointy);
            currmodel.GetModelSettings().Crosses().Add(newcross);
            NewRoadCrossToCross(one, newcross, name);
        }


    }
}
